package es.bwain.xprt.test;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.bwain.balls.Car;
import es.bwain.balls.Model;
import es.bwain.xprt.action.Action;
import es.bwain.xprt.action.ResponseFormat;

public class DoItBetterAction extends Action {

	private String car;
	private Long id;
	
	public String getCar() {
		return car;
	}
	
	public void setCar(String car) {
		this.car = car;
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@SuppressWarnings("unchecked")
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		
		Car car1 = new Car();
		car1.setId(1L);
		car1.setName("Mondeo");
		
		Model model1 = new Model();
		model1.setId(1L);
		model1.setName("Turismo");
		car1.setModel(model1);
		
		Car car2 = new Car();
		car2.setId(2L);
		car2.setName("Ka");
		Model model2 = new Model();
		model2.setId(2L);
		model2.setName("Deportivo <la\"la\"la>");
		car2.setModel(model2);
		
		Car car3 = new Car();
		car3.setId(3L);
		car3.setName("Land Rover");
		Model model3 = new Model();
		model3.setId(3L);
		model3.setName("4x4");
		car3.setModel(model3);
		
		List cars = new ArrayList();
		cars.add(car1);
		cars.add(car2);
		cars.add(car3);
		
		putBall("cars", cars);
		

	}
	
	public void executeJson(HttpServletRequest request, HttpServletResponse response) {
		execute(request, response);
		this.setResponseFormat(ResponseFormat.JSON);
	}
	
}
